<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>EFAK - 主题详情</title>
    <!-- 本地CSS文件 -->
    <th:block th:replace="~{public/common :: css}"></th:block>
    <!-- 本地JS文件 -->
    <!-- 主题详情JS文件 -->
    <th:block th:replace="~{public/common :: js}"></th:block>

    <style>
        /* 主要内容区域布局 */
        .main-content-mobile {
            margin-left: 0 !important;
            width: 100% !important;
        }

        .main-content {
            transition: margin-left 0.3s ease-in-out;
        }

        @media (max-width: 1024px) {
            .main-content {
                margin-left: 0 !important;
            }
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 1.5rem;
            margin-bottom: 2rem;
        }

        @media (max-width: 1200px) {
            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        @media (max-width: 768px) {
            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
                gap: 1rem;
            }
        }

        @media (max-width: 480px) {
            .stats-grid {
                grid-template-columns: 1fr;
            }
        }

        .stat-card {
            background: white;
            border-radius: 1.25rem;
            padding: 1.5rem;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            border: 1px solid rgba(229, 231, 235, 0.6);
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            min-height: 120px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }

        .stat-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #165DFF, #36CFC9);
        }

        .stat-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
        }

        .stat-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 1.5rem;
        }

        .stat-title {
            font-size: 1.125rem;
            font-weight: 600;
            color: #1F2937;
        }

        .stat-icon {
            width: 2.5rem;
            height: 2.5rem;
            border-radius: 0.75rem;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.25rem;
            color: white;
        }

        .stat-icon.messages {
            background: linear-gradient(135deg, #165DFF, #4F8AFF);
        }

        .stat-icon.size {
            background: linear-gradient(135deg, #52C41A, #73D13D);
        }

        .stat-icon.producers {
            background: linear-gradient(135deg, #FAAD14, #FFC53D);
        }

        .stat-icon.consumers {
            background: linear-gradient(135deg, #FF4D4F, #FF7875);
        }

        .stat-value {
            font-size: 1.875rem;
            font-weight: 700;
            color: #165DFF;
            margin-bottom: 0.25rem;
        }

        .stat-description {
            color: #6B7280;
            font-size: 0.8rem;
            line-height: 1.2;
        }

        .content-section {
            background: white;
            border-radius: 1.25rem;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            border: 1px solid rgba(229, 231, 235, 0.6);
        }

        .section-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 1.5rem;
            padding-bottom: 1rem;
            border-bottom: 2px solid #F3F4F6;
        }

        .section-title {
            font-size: 1.375rem;
            font-weight: 600;
            color: #1F2937;
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }

        .section-icon {
            width: 2rem;
            height: 2rem;
            border-radius: 0.5rem;
            background: linear-gradient(135deg, #165DFF, #4F8AFF);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.875rem;
        }

        .partition-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 1rem;
        }

        .partition-table th {
            background: #F9FAFB;
            padding: 1rem 1.25rem;
            text-align: left;
            font-weight: 600;
            color: #4B5563;
            border-bottom: 2px solid #E5E7EB;
            font-size: 0.875rem;
        }

        .partition-table td {
            padding: 1rem 1.25rem;
            border-bottom: 1px solid #E5E7EB;
            color: #374151;
        }

        .partition-table tr:hover {
            background: #F9FAFB;
        }

        .status-badge {
            display: inline-flex;
            align-items: center;
            padding: 0.375rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.75rem;
            font-weight: 500;
            gap: 0.25rem;
        }

        .status-badge.leader {
            background: #DCFCE7;
            color: #15803D;
        }

        .status-badge.follower {
            background: #E0F2FE;
            color: #0369A1;
        }

        .status-badge.stable {
            background: #DCFCE7;
            color: #15803D;
        }

        .status-badge.rebalancing {
            background: #FEF3C7;
            color: #D97706;
        }

        .chart-container {
            height: 350px;
            margin: 1rem 0;
            position: relative;
        }

        .empty-state {
            text-align: center;
            padding: 3rem 2rem;
            color: #6B7280;
        }

        .empty-state i {
            font-size: 3rem;
            margin-bottom: 1rem;
            opacity: 0.5;
        }

        .refresh-btn {
            background: linear-gradient(135deg, #165DFF, #4F8AFF);
            color: white;
            border: none;
            border-radius: 0.75rem;
            padding: 0.75rem 1.5rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .refresh-btn:hover {
            background: linear-gradient(135deg, #0F4FFF, #3F7AFF);
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(22, 93, 255, 0.3);
        }

        /* 时间范围选择器样式 */
        .time-range-select {
            min-width: 140px;
        }

        .select2-container--default .select2-selection--single {
            height: 38px;
            border: 1px solid #d1d5db;
            border-radius: 0.5rem;
            transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
        }

        .select2-container--default .select2-selection--single:focus-within,
        .select2-container--default.select2-container--open .select2-selection--single {
            border-color: #165DFF;
            box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.1);
        }

        .select2-container--default .select2-selection--single .select2-selection__rendered {
            color: #374151;
            line-height: 36px;
            padding-left: 12px;
            padding-right: 32px;
            font-size: 0.875rem;
            white-space: nowrap !important;
        }

        .select2-container--default .select2-selection--single .select2-selection__arrow {
            height: 36px;
            right: 8px;
            width: 20px;
        }

        .select2-container--default .select2-selection--single .select2-selection__arrow b {
            border-color: #6b7280 transparent transparent transparent;
            border-style: solid;
            border-width: 5px 4px 0 4px;
            height: 0;
            left: 50%;
            margin-left: -4px;
            margin-top: -2px;
            position: absolute;
            top: 50%;
            width: 0;
        }

        .select2-dropdown {
            border: 1px solid #e5e7eb;
            border-radius: 0.5rem;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
            z-index: 9999;
        }

        .select2-results__option {
            padding: 10px 12px;
            font-size: 0.875rem;
            cursor: pointer;
            transition: all 0.15s ease-in-out;
            white-space: nowrap !important;
        }

        .select2-results__option--highlighted {
            background-color: #f3f4f6;
            color: #374151;
        }

        .select2-results__option[aria-selected="true"] {
            background-color: #165DFF;
            color: white;
        }

        /* 分页样式 */
        .pagination-container {
            display: flex;
            justify-content: between;
            align-items: center;
            margin-top: 1rem;
            padding: 1rem 0;
        }

        .pagination {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .pagination button {
            padding: 0.5rem 0.75rem;
            border: 1px solid #d1d5db;
            background: white;
            color: #374151;
            border-radius: 0.375rem;
            cursor: pointer;
            transition: all 0.2s;
            font-size: 0.875rem;
        }

        .pagination button:hover:not(:disabled) {
            background: #f3f4f6;
            border-color: #9ca3af;
        }

        .pagination button:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }

        .pagination button.active {
            background: #165DFF;
            border-color: #165DFF;
            color: white;
        }

        .pagination-info {
            font-size: 0.875rem;
            color: #6b7280;
        }

        /* 美化提示框样式 */
        .custom-tooltip {
            position: relative;
            display: inline-block;
        }

        .custom-tooltip .tooltip-content {
            visibility: hidden;
            opacity: 0;
            position: absolute;
            z-index: 1000;
            bottom: 125%;
            left: 50%;
            transform: translateX(-50%);
            background-color: #1f2937;
            color: white;
            text-align: center;
            border-radius: 6px;
            padding: 8px 12px;
            font-size: 12px;
            white-space: nowrap !important;
            transition: all 0.3s ease;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        }

        .custom-tooltip .tooltip-content::after {
            content: "";
            position: absolute;
            top: 100%;
            left: 50%;
            transform: translateX(-50%);
            border: 5px solid transparent;
            border-top-color: #1f2937;
        }

        .custom-tooltip:hover .tooltip-content {
            visibility: visible;
            opacity: 1;
        }

        /* 对话框样式 */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10000;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
        }

        .modal-overlay.active {
            opacity: 1;
            visibility: visible;
        }

        .modal-content {
            background: white;
            border-radius: 1rem;
            max-width: 800px;
            width: 90%;
            max-height: 80vh;
            overflow-y: auto;
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
        }

        .modal-header {
            padding: 1.5rem;
            border-bottom: 1px solid #e5e7eb;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .modal-body {
            padding: 1.5rem;
        }

        .message-item {
            border: 1px solid #e5e7eb;
            border-radius: 0.5rem;
            padding: 1rem;
            margin-bottom: 1rem;
            background: #f9fafb;
        }

        .message-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 0.5rem;
            font-size: 0.875rem;
            color: #6b7280;
        }

        .message-content {
            font-family: 'Courier New', monospace;
            background: white;
            padding: 0.75rem;
            border-radius: 0.375rem;
            border: 1px solid #e5e7eb;
            font-size: 0.875rem;
            overflow-x: auto;
        }

        .loading-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(255, 255, 255, 0.9);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 9999;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
        }

        .loading-overlay.active {
            opacity: 1;
            visibility: visible;
        }

        .loading-spinner {
            width: 3rem;
            height: 3rem;
            border: 3px solid #E5E7EB;
            border-top: 3px solid #165DFF;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(360deg);
            }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .content-section {
                padding: 1.5rem;
            }

            .section-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 1rem;
            }

            .flex.items-center.justify-between {
                flex-direction: column;
                align-items: flex-start;
                gap: 1rem;
            }

            .flex.items-center.gap-6 {
                flex-direction: column;
                align-items: flex-start;
                gap: 0.5rem;
            }
        }
    </style>
</head>

<body class="bg-light-bg text-dark font-inter">
    <div class="flex min-h-screen overflow-hidden">
        <!-- 侧边栏 -->
        <th:block th:replace="~{public/navbar :: navbar}"></th:block>

        <!-- 移动端遮罩层 -->
        <th:block th:replace="~{public/navbar :: overlay}"></th:block>

        <!-- 加载遮罩 -->
        <div class="loading-overlay" id="loadingOverlay">
            <div class="loading-spinner"></div>
        </div>

        <!-- 主内容区域 -->
        <div class="flex-1 flex flex-col overflow-hidden main-content" style="margin-left: 256px;">
            <!-- 顶部导航栏 -->
            <th:block th:replace="~{public/header :: header}"></th:block>

            <!-- 页面内容 -->
            <main class="flex-1 overflow-y-auto p-6 scrollbar-hide pt-20">
                <!-- 页面标题 -->
                <div class="flex items-center justify-between mb-6">
                    <div>
                        <h1 class="text-2xl font-bold text-gray-900" id="topicName" th:text="${topicName}">主题加载中...</h1>
                        <div class="flex items-center gap-6 mt-2 text-sm text-gray-600">
                            <span>分区数: <span id="partitionCount" class="font-medium">-</span></span>
                            <span>副本因子: <span id="replicationFactor" class="font-medium">-</span></span>
                        </div>
                    </div>
                    <button class="refresh-btn" onclick="refreshTopicData()">
                        <i class="fa fa-sync-alt"></i>
                        刷新数据
                    </button>
                </div>

                <!-- 统计卡片网格 -->
                <div class="stats-grid">
                    <div class="stat-card">
                        <div class="stat-header">
                            <div class="stat-title">消息总数</div>
                            <div class="stat-icon messages">
                                <i class="fa fa-envelope"></i>
                            </div>
                        </div>
                        <div class="stat-value" id="messageCount">0</div>
                        <div class="stat-description">累计处理的消息数量</div>
                    </div>

                    <div class="stat-card">
                        <div class="stat-header">
                            <div class="stat-title">数据大小</div>
                            <div class="stat-icon size">
                                <i class="fa fa-database"></i>
                            </div>
                        </div>
                        <div class="stat-value" id="messageSize">0 MB</div>
                        <div class="stat-description">主题占用的存储空间</div>
                    </div>

                    <div class="stat-card">
                        <div class="stat-header">
                            <div class="stat-title">写入速度</div>
                            <div class="stat-icon producers">
                                <i class="fa fa-upload"></i>
                            </div>
                        </div>
                        <div class="stat-value" id="writeSpeed">0 MB/s</div>
                        <div class="stat-description">每秒消息写入字节数</div>
                    </div>

                    <div class="stat-card">
                        <div class="stat-header">
                            <div class="stat-title">读取速度</div>
                            <div class="stat-icon consumers">
                                <i class="fa fa-download"></i>
                            </div>
                        </div>
                        <div class="stat-value" id="readSpeed">0 MB/s</div>
                        <div class="stat-description">每秒消息读取字节数</div>
                    </div>
                </div>

                <!-- 消息流量图表 -->
                <div class="content-section">
                    <div class="section-header">
                        <div class="section-title">
                            <div class="section-icon">
                                <i class="fa fa-line-chart"></i>
                            </div>
                            生产消息流量趋势
                        </div>
                        <div class="flex items-center gap-3 whitespace-nowrap">
                            <label class="text-sm font-medium text-gray-600 flex-shrink-0">时间范围:</label>
                            <select id="timeRangeSelect" class="time-range-select" onchange="updateTimeRange()">
                                <option value="1h">最近1小时</option>
                                <option value="6h">最近6小时</option>
                                <option value="1d" selected>最近1天</option>
                                <option value="3d">最近3天</option>
                                <option value="7d">最近7天</option>
                            </select>
                        </div>
                    </div>
                    <div class="chart-container">
                        <canvas id="messageFlowChart"></canvas>
                    </div>
                </div>

                <!-- 分区信息 -->
                <div class="content-section">
                    <div class="section-header">
                        <div class="section-title">
                            <div class="section-icon">
                                <i class="fa fa-th-large"></i>
                            </div>
                            分区详情
                        </div>
                    </div>
                    <div class="overflow-x-auto">
                        <table class="partition-table">
                            <thead>
                                <tr>
                                    <th>分区ID</th>
                                    <th>Leader</th>
                                    <th>副本列表</th>
                                    <th>ISR</th>
                                    <th>消息数量</th>
                                    <th>Preferred Leader</th>
                                    <th>Under Replicated</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody id="partitionTableBody">
                                <tr>
                                    <td colspan="8" class="empty-state">
                                        <i class="fa fa-spinner fa-spin"></i>
                                        <div>正在加载分区信息...</div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="pagination-container">
                        <div class="pagination-info" id="partitionPaginationInfo">
                            显示 0 - 0 条，共 0 条
                        </div>
                        <div class="pagination" id="partitionPagination">
                            <button onclick="changePartitionPage('prev')" id="partitionPrevBtn" disabled>上一页</button>
                            <span id="partitionPageNumbers"></span>
                            <button onclick="changePartitionPage('next')" id="partitionNextBtn" disabled>下一页</button>
                        </div>
                    </div>
                </div>

                <!-- 消费者组信息 -->
                <div class="content-section">
                    <div class="section-header">
                        <div class="section-title">
                            <div class="section-icon">
                                <i class="fa fa-users"></i>
                            </div>
                            消费者组
                        </div>
                    </div>
                    <div id="consumerGroupsContent">
                        <div class="empty-state">
                            <i class="fa fa-spinner fa-spin"></i>
                            <div>正在加载消费者组信息...</div>
                        </div>
                    </div>
                    <div class="pagination-container" id="consumerGroupsPagination" style="display: none;">
                        <div class="pagination-info" id="consumerGroupsPaginationInfo">
                            显示 0 - 0 条，共 0 条
                        </div>
                        <div class="pagination" id="consumerGroupsPaginationControls">
                            <button onclick="changeConsumerGroupPage('prev')" id="consumerGroupPrevBtn"
                                disabled>上一页</button>
                            <span id="consumerGroupPageNumbers"></span>
                            <button onclick="changeConsumerGroupPage('next')" id="consumerGroupNextBtn"
                                disabled>下一页</button>
                        </div>
                    </div>
                </div>

                <!-- 配置信息 -->
                <div class="content-section">
                    <div class="section-header cursor-pointer" onclick="toggleConfigSection()">
                        <div class="section-title">
                            <div class="section-icon">
                                <i class="fa fa-cog"></i>
                            </div>
                            主题配置
                        </div>
                        <i id="configToggleIcon"
                            class="fa fa-chevron-down text-gray-400 transition-transform duration-200"></i>
                    </div>
                    <div id="configContent" class="hidden">
                        <div class="empty-state">
                            <i class="fa fa-spinner fa-spin"></i>
                            <div>正在加载配置信息...</div>
                        </div>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <!-- 消息预览对话框 -->
    <div class="modal-overlay" id="messagePreviewModal" onclick="closeMessagePreviewOnOverlay(event)">
        <div class="modal-content" onclick="event.stopPropagation()">
            <div class="modal-header">
                <h3 class="text-lg font-semibold">分区消息预览</h3>
                <button onclick="closeMessagePreview()" class="text-gray-400 hover:text-gray-600">
                    <i class="fa fa-times text-xl"></i>
                </button>
            </div>
            <div class="modal-body">
                <div class="mb-4">
                    <span class="text-sm text-gray-600">主题:</span>
                    <span class="font-medium" id="previewTopicName"></span>
                    <span class="text-sm text-gray-600 ml-4">分区:</span>
                    <span class="font-medium" id="previewPartitionId"></span>
                </div>
                <div id="messageList">
                    <div class="text-center py-8">
                        <i class="fa fa-spinner fa-spin text-2xl text-gray-400"></i>
                        <div class="mt-2 text-gray-600">正在加载消息...</div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 主题详情JS文件 -->
    <script th:src="@{/js/system/topic-detail.js}"></script>
</body>

</html>